package com.eascs.web.demo.rest;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.site.controller.BaseRestController;
import com.eascs.site.view.MessageRestResult;
import com.eascs.web.demo.form.SuccessResponseForm;
import com.eascs.web.demo.response.SuccessResponse;

@RestController
public class SampleRestController extends BaseRestController {
	private final Logger logger = LoggerFactory.getLogger(SampleRestController.class);
//	@Inject
//	Hello hello;
/*	
	public Hello getHello() {
		return hello;
	}

	public void setHello(Hello hello) {
		this.hello = hello;
	}
*/
	@RequestMapping(value = "/demo/rest/", method = RequestMethod.GET)
	public String[] index() {
		logger.info("SampleRestController index ...");
		return new String[] { "index" };
	}

	@RequestMapping(value = "/demo/rest/form", method = RequestMethod.GET)
	private RestDemoForm restDemoForm(RestDemoForm restDemoForm) {
		return restDemoForm;
	}
	
	@RequestMapping(value = "/demo/rest/string", method = RequestMethod.GET)
	public String string() {
		logger.info("SampleRestController index ...");
		return "errorView";
	}

	@RequestMapping(value = "/demo/rest/success", method = RequestMethod.GET)
	public MessageRestResult success() {
		logger.debug("SampleRestController index ...");
		//Hello hello1 = ApplicationContextUtil.getBean(Hello.class);
		
		//logger.error("=========="+hello1.sayHello("this is demo"));
	//	logger.error("=========="+hello.sayHello("this is demo"));
		return MessageRestResult.info("success");
	}

	@RequestMapping(value = "/demo/rest/success-response", method = RequestMethod.GET)
	public SuccessResponse successResponse(SuccessResponseForm successResponseForm) {
		logger.debug("SampleRestController index ...");
		SuccessResponse successResponse = new SuccessResponse();
		successResponse.setState(0);
		successResponse.setMessage(successResponseForm.getData());
		return successResponse;
	}

	@RequestMapping(value = "/demo/rest/exception", method = RequestMethod.GET)
	public String[] exception() {
		logger.debug("SampleRestController exception ...");
		if (logger != null)
			throw new RuntimeException("test exception");
		return new String[] { "exception" };
	}
}